/*
	路由表
*/
package router

import (
	"data/view/approval"
	"data/view/auth"
	"data/view/clock"
	"data/view/getui"
	"data/view/interview"
	"data/view/kv"
	"data/view/login"
	"data/view/mybaidu"
	"data/view/news"
	"data/view/other"
	"data/view/paper"
	"data/view/question"
	"data/view/school"
	"data/view/statistics"
	"data/view/student"
	"data/view/team"
	"data/view/user"
	"data/view/verify"
	"data/view/version_s"

	"github.com/ant0ine/go-json-rest/rest"
)

//
var DefaultRouler = []*rest.Route{
	//管理员登录授权 相关
	Post("/login", login.M_login.OnLogin),              //用户登录pc
	Post("/loginex", login.M_login.OnLoginEx),          //用户登录
	Post("/check_token", login.M_login.CheckToken),     //验证token
	Post("/refresh_token", login.M_login.RefreshToken), //刷新token管理员
	Post("/go/verify", verify.M_verify.GetVerify),      //获取验证码
	Post("/change_pwd", login.ChangePwd),               //修改密码
	Post("/third_login", login.ThirdLogin),             //第三方登录
	Post("/bind_phone", login.OnBindPhone),             //绑定手机号
	Post("/change_pwdex", login.ChangePwdEx),           //修改密码

	//用户相关
	Post("/user/get_role_config", user.GetRoleConfig), //获取用户角色
	// Post("/user/get_parent", user.GetParent),          //获取上级用户
	Post("/user/add", user.Add),         //新增用户
	Post("/user/get_all", user.GetAll),  //获取用户
	Post("/user/action", user.DoAction), //编辑删除用户
	// Post("/user/get_levels", user.GetLevels), //获取上下级用户
	Post("/user/role_action", user.RoleAction), //新增编辑用户角色

	//团队相关
	Post("/team/add", team.Add),                     //添加团队
	Post("/team/action", team.DoAction),             //编辑删除团队
	Post("/team/get_all_detail", team.GetAllDetail), //获取全部团队详情

	//权限管理
	Post("/auth/get_all", auth.GetAll), //拉取权限
	Post("/auth/update", auth.Update),  //更新权限

	//题库相关
	// Post("/question/add", question.Add),       //添加题目
	Post("/question/update", question.Update),    //编辑题目
	Post("/question/get_type", question.GetType), //获取题目类别
	Post("/question/delete", question.Delete),    //删除题目
	Post("/question/search", question.Search),    //搜索题目

	//试卷相关
	Post("/paper/create", paper.CreatePaper),            //出卷
	Post("/paper/update", paper.UpdatePaper),            //编辑试卷
	Post("/paper/get_all", paper.GetAllPaper),           //获取全部试卷
	Post("/paper/get_qrcode", paper.GetQrcode),          //生成试卷二维码
	Post("/paper/detail", paper.GetPaperDetail),         //获取试卷详情
	Post("/paper/submit", paper.Submit),                 //交卷
	Post("/paper/get_user_answer", paper.GetUserAnswer), //查看某一试卷答题记录
	Post("/paper/judge_score", paper.JudgeScore),        //评分
	Post("/paper/get_score", paper.GetScore),            //考生查看答卷

	//统计分析
	Post("/statistics/score", statistics.ScoreAnalysis),       //成绩分析
	Post("/statistics/question", statistics.QuestionAnalysis), //单选试题分析

	//审批流相关
	Post("/approval/add_type", approval.OnAddType),                    //添加一个审批类型
	Post("/approval/get_type", approval.OnGetType),                    //获取审批类型
	Post("/approval/delete_type", approval.OnDeleteType),              //删除审批类型
	Post("/approval/update_template", approval.UpdateTemplate),        //编辑审批模板
	Post("/approval/get_all_template", approval.GetAllTemplate),       //获取审批模板
	Post("/approval/get_template_detail", approval.GetTemplateDetail), //获取审批模板详情
	Post("/approval/submit", approval.Submit),                         //提交审批
	Post("/approval/get_mine_submit", approval.GetMineSubmit),         //我发起的审批
	Post("/approval/cancel", approval.Cancel),                         //撤销审批
	Post("/approval/get_detail", approval.GetDetail),                  //审批详情
	Post("/approval/get_mine_approval", approval.GetMineApproval),     //我审批的
	Post("/approval/deal", approval.Deal),                             //审批
	Post("/approval/get_mine_copy", approval.GetMineCopy),             //抄送我的

	Get("/version/check", version_s.Check), //检测最新版本号

	//数据字典
	Post("/kv/action", kv.Action),         //新增或更新数据字典
	Post("/kv/get_all", kv.GetAll),        //获取全部数据字典
	Post("/kv/delete", kv.Delete),         //删除数据字典
	Post("/kv/update_ref", kv.UpdateRef),  //修改字典关联
	Post("/kv/get_ref_all", kv.GetRefAll), //获取全部字典关联

	//学校相关
	Post("/school/action", school.Action),  //编辑或新增学校信息
	Post("/school/get_all", school.GetAll), //获取全部学校信息

	//面试相关
	Post("/interview/create_sheet", interview.CreateSheet),       //创建面试单
	Post("/interview/get_interviewer", interview.GetInterviewer), //查询面试官

	//其他
	Post("/other/region_action", other.RegionAction), //编辑或新增省市区
	Post("/other/get_region", other.GetRegion),       //获取省市区

	//新闻相关
	Post("/news/action", news.Action),        //编辑或新增新闻
	Post("/news/delete", news.Delete),        //删除新闻
	Post("/news/get_all", news.GetAll),       //获取全部新闻
	Post("/news/update_pic", news.UpdatePic), //编辑图片

	//考勤打卡
	Post("/clock/get_range", clock.GetRange), //获取打卡范围信息
	Post("/clock/action", clock.Action),      //打卡或更新打卡
	Post("/clock/get_mine", clock.GetMine),   //获取自己当天打卡记录

	//学生相关
	Post("/student/add", student.Add),        //学生录入
	Post("/student/get_all", student.GetAll), //获取自己招生的全部学生信息
	Post("/student/verify", student.Verify),  //审核学生信息
	//ocr
	Post("/ocr/check", mybaidu.OnCheckOcr),              //开始ocr
	Post("/ocr/bind", mybaidu.OnBindOcr),                //开始绑定ocr
	Post("/getuserbyphone", login.OnGetUserInfoByPhone), //通过手机获取用户信息
	Post("/getuserbyphoto", login.OnGetUserInfoByPhoto), //通过ocr获取用户信息

	//个推
	Post("/getui/bind", getui.BindGetui), //绑定个推
}

/*
	默认初始化
*/
func OnInitRoter(api *rest.Api) (router rest.App, err error) {
	OnCheckRoter(DefaultRouler...)
	router, err = rest.MakeRouter(
		DefaultRouler...,
	)

	return
}

/*
	检测重复
*/
func OnCheckRoter(routes ...*rest.Route) {
	mp := make(map[string]int)
	for _, v := range routes {
		if mp[v.PathExp] == 1 {
			panic("============" + v.PathExp + " : is repeat in rooter.go.================")
		} else {
			mp[v.PathExp] = 1
		}
	}
}
